<template>
  <div class="tabcontrol">
    <div v-for="(item,index) in titles" :key="index" :class="{active:currentIndex==index}" class="tabitem" @click="itemClick(index)">
      <span>{{item}}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "Tabcontrol",
  data(){
    return {
      currentIndex: 0,
    }
  },
  methods: {
    itemClick(index){
      this.currentIndex = index;
      // console.log("tets");
      this.$emit("tabclick",index);
    }
  },
  props: {
    titles: {
      type: Array,
      default(){
        return []
      }
    }
  }
}
</script>

<style scoped>
  .tabcontrol{
    display: flex;
    width: 100%;
    background-color:#fff;
    text-align: center;
    height: 35px;
    line-height: 30px;
    font-size: 15px;
    position: sticky;
    top: 44px;
    
  }

  .tabitem{
    flex:1
  }

  .active span{
    padding: 5px;
    border-bottom: 3px solid pink;
    color: pink;
    
  }
</style>